@extends('layouts.back_stage')
@section('content')
    <style>
        .xing{color:red;}
        .form_ul{width:100%;height:30px;margin-bottom:20px;}
        .form_li{width:260px;line-height:30px;margin-right:10px;float:left;font-size:14px;}
        .form-control{width:200px;font-size:14px;float:right;}
        .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control{background:#fff;}
        .input-icon {width: 200px;position: relative;float:right;}
        .input-icon i {position: absolute;top: 0;right: 10px;font-style:normal;}
        label{margin-right: 15px;}
        input[type='radio']{
            width:18px!important;
            height:18px!important;
            margin-top: 6px!important;
            margin-right: 5px!important;
        }
        input[type='radio']:checked{
            width:18px!important;
            height:18px!important;
            margin-top: 6px!important;
            margin-right: 5px!important;
        }
        .sp{float:right;}
        .bottom_sure{padding: 30px 30px;text-indent:100px;}
        .sureB{margin-right:20px;}
    </style>
    <!-- 吊牌生产-->
    <div class="container">
        <!-- 主体-->
        <div class="row">
            <div style="margin:30px;"><h3>吊牌信息</h3></div>
                <div style="width:90%;margin-left:100px;">
                    <div class="form-group">
                        <ul class="form_ul">
                            <li class="form_li"><span class="xing">*</span>类型：
                                <select class="form-control cate1 disTrue bgTips">
                                    <option value="">请选择大类</option>
                                    @foreach ($pcate as $kk => $vv)
                                        @if($vv->pid==0)
                                        <option value="{{$vv->id}}" @if($infos->cate_1 == $vv->id)selected="selected" @endif>{{$vv->category_name}}</option>
                                        @endif
                                    @endforeach
                                </select>
                            </li>
                            <li class="form_li" style="width: 210px;">
                                <select class="form-control cate2 disTrue bgTips">
                                    <option value="">请选择中类</option>
                                    @if(!empty($infos->cate_2))
                                    @foreach ($pcate as $kk => $vv)
                                            @if($vv->pid==$infos->cate_1)
                                            <option value="{{$vv->id}}" @if($infos->cate_2 == $vv->id)selected="selected" @endif>{{$vv->category_name}}</option>
                                            @endif
                                    @endforeach
                                    @endif
                                </select>
                            </li>
                            <li class="form_li" style="width: 210px;">
                                <select class="form-control cate3 disTrue bgTips">
                                    <option value="">请选择小类</option>
                                    @if(!empty($infos->cate_3))
                                        @foreach ($pcate as $kk => $vv)
                                            @if($vv->pid==$infos->cate_2)
                                                <option value="{{$vv->id}}" @if($infos->cate_3 == $vv->id)selected="selected" @endif>{{$vv->category_name}}</option>
                                            @endif
                                        @endforeach
                                    @endif
                                </select>
                            </li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li"><span class="xing">*</span>品名：<input disabled class="form-control name bgTips" type="text" placeholder="品名" value="{{$infos->name}}" /></li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li" style="width:260px;"><span class="xing">*</span>系列：
                                <select class="form-control brand_id disTrue bgTips">
                                    <option value="">请选择系列</option>
                                    @foreach ($brands as $k => $v)
                                        <option value="{{$k}}" @if($infos->brand_id == $k)selected="selected" @endif >{{$v}}</option>
                                    @endforeach
                                </select>
                            </li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li"><span class="xing">*</span>款号：<input type="text" class="form-control girard disTrue bgTips" value="{{$infos->girard}}" autocomplete="off" autocorrect="off" placeholder="请输入款号" style="text-transform:uppercase"></li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li"><span class="xing">*</span>颜色：<input class="form-control color" type="text" value="{{$infos->color}}" placeholder="请输入颜色" autocomplete="off" autocorrect="off" /></li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li"><span class="xing">*</span>价格：<input class="form-control price disTrue bgTips" type="text" value="{{$infos->price}}" placeholder="请输入价格" autocomplete="off" autocorrect="off" /></li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li" style="width:290px;"><span class="xing">*</span>尺码规格：
                                <select class="form-control size_speci_id disTrue bgTips">
                                    <option value="">请选择尺码规格</option>
                                    @if(count($size_infos))
                                        @foreach($size_infos as $k => $v)
                                            <option value="{{$v->id}}" @if($infos->size_speci_id == $v->id)selected="selected" @endif>{{$v->size_speci}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </li>
                            <li class="form_li" style="margin-left:10px;"><span class="xing roleSp">*</span>尺码：<input class="form-control size" type="text" value="{{$infos->size}}" placeholder="请输入尺码" autocomplete="off" autocorrect="off" style="text-transform:uppercase" /></li>
                            <li class="form_li" style="margin-left:10px;width: 420px;"> 举例: <span class="example"><?php echo trim($select_size_infos,',');?></span>（用英文逗号分隔）</li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li" style="width:290px;"><span class="xing">*</span>执行标准：
                                <select class="form-control standard_id">
                                    <option value="">请选择类别</option>
                                    @if(count($exec_standard))
                                        @foreach($exec_standard as $k => $v)
                                            @if($v->pid==0)
                                            <option value="{{$v->id}}" @if($infos->standard_id==$v->id) selected="selected" @endif>{{$v->name}}</option>
                                            @endif
                                        @endforeach
                                    @endif
                                </select>
                            </li>
                            <li class="form_li" style="width:210px;">
                                <select class="form-control exec_standard">
                                    <option value="">请选择执行标准</option>
                                    @if(count($exec_standard))
                                        @foreach($exec_standard as $k => $v)
                                            @if($v->pid==$infos->standard_id)
                                            <option value="{{$v->code}}" @if($infos->exec_standard==$v->code) selected="selected" @endif>{{$v->name}}{{$v->code}}</option>
                                            @endif
                                        @endforeach
                                    @endif
                                </select>
                            </li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li" style="width:400px;"><span class="xing">*</span>安全类别：
                                <span class="input-icon icon-right" style="width:310px;">
                                    <label><input type="radio" name="safety_class" value="GB31701 婴幼儿用品" @if($infos->safety_class=='GB31701 婴幼儿用品') checked @endif><span class="sp">婴幼儿用品</span></label>
                                    <label><input type="radio" name="safety_class" value="GB31701 B类" @if($infos->safety_class=='GB31701 B类' || empty($infos->safety_class)) checked @endif ><span class="sp">儿童B类</span></label>
                                    <label><input type="radio" name="safety_class" value="GB18401-2010 B类" @if($infos->safety_class=='GB18401-2010 B类') checked @endif ><span class="sp">成人B类</span></label>
                                </span>
                            </li>
                        </ul>
                        <ul class="form_ul" style="height:100px;">
                            <li class="form_li" style="width:550px;"><span class="xing">*</span>成分：
                                <textarea class="form-control ingredient disTrue bgTips" placeholder="请输入成分" style="float: right;width: 460px;height: 100px;resize:none;">{{$infos->ingredient}}</textarea>
                            </li>
                            <li class="form_li" style="width: 400px;">举例: 65%羊毛(面布)/50%聚酯纤维(面布)（用"/"分隔）</li>
                        </ul>
                        <ul class="form_ul">
                            <li class="form_li" style="width:290px;"><span class="xing roleSp">*</span>打印数量：
                                <span class="input-icon icon-right">
                                    <input type="text" class="form-control nums" value="{{$infos->nums}}" autocomplete="off" autocorrect="off" maxlength="5" placeholder="请输入打印数量">
                                    <i>件</i>
                                </span>
                            </li>
                        </ul>
                        <ul class="form_ul">
                            <div class="bottom_sure">
                                <?php $data = Auth::guard('admin')->user()->user_role();?>
                                @if(in_array('62',$data))   {{--仓库人--}}
                                <button class="btn btn-info daYin" type="button">打印</button>
                                @elseif(in_array('63',$data) && $_GET['role']==1)   {{--生产条码的人--}}
                                <button class="btn btn-info daYin" type="button">打印</button>
                                @endif
                                @if(in_array('65',$data) && $_GET['role']==0)   {{--生产条码的人--}}
                                    <button class="btn btn-info sureB" type="button">确定</button>
                                    <button class="btn btn-info sureD" type="button">清空</button>
                                @endif

                            </div>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- /主体-->
    </div>
    <!-- /吊牌生产-->
    <script>
        var url=window.location.href;
        var tab=url.split("=");
        var role=tab[2];
        if(role==0){
            $(".roleSp").hide();
        }else{
            $(".roleSp").show();
            $(".disTrue").attr("disabled","true");
            $(".bgTips").css("background","#F6F6F6")
        }

        /*大中小分类三级联动*/
        $('.cate1').change(function () {
            $('.name').val("");
            $('.cate2').html("<option value=''>请选择中类</option>");
            $('.cate3').html("<option value=''>请选择小类</option>");
        });
        $('.cate1').change(function () {
            $('.name').val("");
            var pid = $(this).val();
            if(pid!=''){
                $.ajax({
                    url:'/cloth/getPidCategory',
                    type:'post',
                    data:{pid:pid},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        $('.cate2').empty();
                        $('.cate2').append("<option value=''>请选择中类</option>");
                        $('.cate3').empty();
                        $('.cate3').append("<option value=''>请选择小类</option>");
                        var info=data.info;
                        if(data.success){
                            for(var i in info){
                                var str="<option value="+info[i].id+">"+info[i].category_name+"</option>";
                                $('.cate2').append(str);
                            }
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            }
        });
        $('.cate2').change(function () {
            $('.name').val("");
            var pid = $(this).val();
            if(pid!=''){
                $.ajax({
                    url:'/cloth/getPidCategory',
                    type:'post',
                    data:{pid:pid},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        $('.cate3').empty();
                        $('.cate3').append("<option value=''>请选择小类</option>");
                        var info=data.info;
                        if(data.success){
                            for(var i in info){
                                var str="<option value="+info[i].id+">"+info[i].category_name+"</option>";
                                $('.cate3').append(str);
                            }
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            }
        });
        /*小类变化拿品名*/
        $('.cate3').change(function (){
            $('.name').val($(".cate3 option:selected").text());
        });
        /*尺码规格变化*/
        $(".size_speci_id").change(function(){
            var size_speci_id=$(this).val();
            $(".size").val("");
            if(size_speci_id!=''){
                $.ajax({
                    url:'/makeQrcode/size-specifications',
                    type:'post',
                    data:{size_speci_id:size_speci_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        //console.log(data);
                        if(data.result.success){
                            $(".example").empty();
                            $(".example").text(data.content);
                            $(".size").val(data.content);
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.result.errorMsg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            }
        });
        /*执行标准变化*/
        $(".standard_id").change(function(){
            var standard_id=$(this).val();
            if(standard_id!=''){
                $.ajax({
                    url:'/makeQrcode/exec-standard',
                    type:'post',
                    data:{standard_id:standard_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    dataType:'json',
                    success:function(data){
                        //console.log(data);
                        var info=data.content;
                        if(data.result.success){
                            $('.exec_standard').empty();
                            $('.exec_standard').html("<option value=''>请选择执行标准</option>");
                            for(var i in info){
                                var str="<option value=\""+info[i].code+"\">"+info[i].name+":"+info[i].code+"</option>";
                                $('.exec_standard').append(str);
                            }
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.result.errorMsg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            }
        });
        /*中文逗号改英文逗号*/
        $(".size").blur(function(){
            var str = $(".size").val();
            str=str.replace(/，/ig,',');
            $(".size").val(str);
        });
        //提交
        $(".sureB").click(function(){
            var url=window.location.href;
            var tab=url.split("=");
            var id=tab[1].split("&")[0];
            var role=tab[2];

            var cate_1=$(".cate1").val();
            if ( cate_1=='' ) {
                tips("请选择大类");
                return false;
            }
            var cate_2=$(".cate2").val();
            if ( cate_2=='' ) {
                tips("请选择中类");
                return false;
            }
            var cate_3=$(".cate3").val();
            if ( cate_3=='' ) {
                tips("请选择小类");
                return false;
            }
            var name=$('.name').val();
            if ( name=='' ) {
                tips("品名不能为空");
                return false;
            }
            var brand_id=$(".brand_id").val();
            if ( brand_id=='' ) {
                tips("请选择系列");
                return false;
            }
            var girard=$(".girard").val();
            var girards=girard.toUpperCase();
            if ( girard=='' ) {
                tips("款号不能为空");
                return false;
            }
            var color=$(".color").val();
            if ( color=='' ) {
                tips("颜色不能为空");
                return false;
            }
            if ( !(/^[\u4e00-\u9fa5]{2,6}$/.test( color ))) {
                tips("颜色为2-6个中文字符");
                return false;
            }
            var price=$(".price").val();
            var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            if(!(exp.test( price ))){
                tips("价格不能为空且为数字");
                return false;
            }
            var size_speci_id=$(".size_speci_id").val();
            if ( size_speci_id=='' ) {
                tips("请选择尺码规格");
                return false;
            }
            var size=$(".size").val();
            var sizes=size.toUpperCase();
            if(role==1){
                if ( size=='' ) {
                    tips("尺码不能为空");
                    return false;
                }
            }
            var standard_id=$(".standard_id").val();
            if ( standard_id=='' ) {
                tips("请选择执行标准类别");
                return false;
            }
            var exec_standard=$(".exec_standard").val();
            if ( exec_standard=='' ) {
                tips("请选择执行标准");
                return false;
            }
            var safety_class=$("input[name='safety_class']:checked").val();
            var ingredient=$(".ingredient").val();
            if ( ingredient=='' ) {
                tips("成分不能为空");
                return false;
            }
            var nums=$(".nums").val();
            if(role==1){
                if ( nums=='' ) {
                    tips("数量不能为空");
                    return false;
                }
                if ( nums==0 ) {
                    tips("数量不能为0");
                    return false;
                }
            }
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                url:'/makeQrcode/qrcode-generate-update',
                type:'post',
                data:{
                    id:id,
                    cate_1:cate_1,
                    cate_2:cate_2,
                    cate_3:cate_3,
                    name:name,
                    brand_id:brand_id,
                    girard:girards,
                    color:color,
                    price:price,
                    size_speci_id:size_speci_id,
                    size:sizes,
                    standard_id:standard_id,
                    exec_standard:exec_standard,
                    safety_class:safety_class,
                    ingredient:ingredient,
                    nums:nums
                },
                dataType:'json',
                success:function (data) {
                    if(data.result.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("保存成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.href='/makeQrcode/make-code-lists';
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.result.errorMsg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
        /*打印*/
        $(".daYin").click(function(){
            var cate_1=$(".cate1").val();
            if ( cate_1=='' ) {
                tips("请选择大类");
                return false;
            }
            var cate_2=$(".cate2").val();
            if ( cate_2=='' ) {
                tips("请选择中类");
                return false;
            }
            var cate_3=$(".cate3").val();
            if ( cate_3=='' ) {
                tips("请选择小类");
                return false;
            }
            var name=$('.name').val();
            if ( name=='' ) {
                tips("品名不能为空");
                return false;
            }
            var brand_id=$(".brand_id").val();
            if ( brand_id=='' ) {
                tips("请选择系列");
                return false;
            }
            var girard=$(".girard").val();
            var girards=girard.toUpperCase();
            if ( girard=='' ) {
                tips("款号不能为空");
                return false;
            }
            var color=$(".color").val();
            if ( color=='' ) {
                tips("颜色不能为空");
                return false;
            }
            if ( !(/^[\u4e00-\u9fa5]{2,6}$/.test( color ))) {
                tips("颜色为2-6个中文字符");
                return false;
            }
            var price=$(".price").val();
            var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            if(!(exp.test( price ))){
                tips("价格不能为空且为数字");
                return false;
            }
            var size_speci_id=$(".size_speci_id").val();
            if ( size_speci_id=='' ) {
                tips("请选择尺码规格");
                return false;
            }
            var size=$(".size").val();
            var sizes=size.toUpperCase();
            if(role==1){
                if ( size=='' ) {
                    tips("尺码不能为空");
                    return false;
                }
            }
            var standard_id=$(".standard_id").val();
            if ( standard_id=='' ) {
                tips("请选择执行标准类别");
                return false;
            }
            var exec_standard=$(".exec_standard").val();
            if ( exec_standard=='' ) {
                tips("请选择执行标准");
                return false;
            }
            var safety_class=$("input[name='safety_class']:checked").val();
            var ingredient=$(".ingredient").val();
            if ( ingredient=='' ) {
                tips("成分不能为空");
                return false;
            }
            var nums=$(".nums").val();
            if ( nums=='' ) {
                tips("数量不能为空");
                return false;
            }
            if ( nums==0 ) {
                tips("数量不能为0");
                return false;
            }


            window.open('/makeQrcode/qrcode-print/?id={{$id}}&cate_1='+cate_1+'&cate_2='+cate_2+'&cate_3='+cate_3+'&name='+name+'&brand_id='+brand_id+'&girard='+girards+'&color='+color+'&price='+price+'&size_speci_id='+size_speci_id+'&size='+sizes+'&standard_id='+standard_id+'&exec_standard='+exec_standard+'&safety_class='+safety_class+'&ingredient='+ingredient+'&nums='+nums);
            //window.open("/makeQrcode/qrcode-print/?cate_1="+cate_1+"&cate_2="+cate_2+"&cate_3="+cate_3+"&name="+name+"&brand_id="+brand_id+"&girard="+girards+"&color="+color+"&price="+price+"&size_speci_id="+size_speci_id+"&size="+sizes+"&exec_standard="+exec_standard+"&safety_class="+safety_class+"&ingredient="+ingredient+"&nums="+nums);
        });
        /*清空按钮*/
        $(".sureD").click(function(){
            $(".form-control").each(function(){
                $(this).val("");
            })
        });
        function tips (txt) {
            $(".faceImg").attr("src","/img/weep.png");
            $(".oHandle").text(txt);
            $(".oSuccess").show(0).delay(1000).hide(0);
        };

        $(".price").bind("input","onpropertychange",function(){
            $(this).val($(this).val().replace(/[^\d.]/g,""));
            $(this).val($(this).val().replace(/\.{2,}/g,"."));
            $(this).val($(this).val().replace(/^\./g,""));
            $(this).val($(this).val().replace(".","$#$").replace(/\./g,"").replace("$#$","."));
            $(this).val($(this).val().replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'));
            if($(this).val().indexOf(".")< 0 && $(this).val() !=""){
                $(this).val(parseFloat($(this).val()));
            }
        });
        $(".nums").bind("input","onpropertychange",function(){
            $(this).val($(this).val().replace(/[^\d]/g,""));
        });
        $(".size").bind("input","onpropertychange",function(){
            $(this).val($(this).val().replace(/[^\d,]/g,""));
        });
    </script>
@endsection
